package com.mythesis.bpel.ui.client;

import org.eclipse.jdt.internal.compiler.batch.Main;

import com.allen_sauer.gwt.dnd.client.PickupDragController;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.FocusPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.HorizontalSplitPanel;
import com.gwtext.client.core.Margins;
import com.gwtext.client.core.RegionPosition;
import com.gwtext.client.widgets.BoxComponent;
import com.gwtext.client.widgets.HTMLPanel;
import com.gwtext.client.widgets.Panel;
import com.gwtext.client.widgets.Toolbar;
import com.gwtext.client.widgets.ToolbarButton;
import com.gwtext.client.widgets.Viewport;
import com.gwtext.client.widgets.layout.AccordionLayout;
import com.gwtext.client.widgets.layout.BorderLayout;
import com.gwtext.client.widgets.layout.BorderLayoutData;
import com.gwtext.client.widgets.layout.FitLayout;
import com.gwtext.client.widgets.menu.CheckItem;
import com.gwtext.client.widgets.menu.Menu;
import com.mythesis.bpel.ui.client.dnd.BpelDragController;
import com.mythesis.bpel.ui.client.dnd.BpelDropController;
import com.mythesis.bpel.ui.client.property.Property;


public class BpelDesigner extends Composite {
	protected BpelPalette bpelPalete;
	protected BpelDesignPanel bpelDesign;
	protected BpelDragController dragController;
	protected BpelDropController dropController;
	
	protected AbsolutePanel boundaryPanel;
	protected HorizontalSplitPanel mainPanel;
	protected HorizontalSplitPanel hSplitPanel;
	protected FocusPanel propertyPanel;
	protected DockPanel dockPanel ;
	
	public BpelDesigner(){
	/*	dockPanel = new DockPanel();
		
		boundaryPanel = new AbsolutePanel();
		boundaryPanel.setSize("100%", "100%");
		dragController = new BpelDragController(boundaryPanel);
		
	    dragController.setBehaviorMultipleSelection(false);
	    bpelPalete = new BpelPalette(dragController);
	    bpelDesign = new BpelDesignPanel();
	    hSplitPanel = new HorizontalSplitPanel();
	    hSplitPanel.setLeftWidget(bpelPalete);
	    hSplitPanel.setRightWidget(bpelDesign);
	    hSplitPanel.setSplitPosition("150px");
	    
	    propertyPanel = new FocusPanel();
	    
	    //propertyPanel.setWidth("10px");
	    mainPanel = new HorizontalSplitPanel();
	    mainPanel.setLeftWidget(hSplitPanel);
	    mainPanel.setRightWidget(propertyPanel);
	    mainPanel.setSplitPosition("960px");
	    
	    boundaryPanel.add(mainPanel);
	    String xml = "<Properties><Property><name>Name</name><type>2</type><default_value>Start</default_value></Property>";
	    xml += "<Property><name>Documentation</name><type>2</type><default_value>nothing</default_value></Property>";
	    xml += "<Property><name>Create Instances</name><type>1</type><default_value>1</default_value></Property></Properties>";
	    propertyPanel.add(new Property(xml));
	    dropController = new BpelDropController(bpelDesign.getDesignPanel());
	    dragController.registerDropController(dropController);
	    
		initWidget(boundaryPanel);*/
		Panel panel = new Panel();
		boundaryPanel = new AbsolutePanel();
		boundaryPanel.setSize("100%", "100%");
		
		panel.setBorder(false);
		panel.setPaddings(15);
		panel.setLayout(new FitLayout());
		
		Panel borderPanel = new Panel();
		borderPanel.setLayout(new BorderLayout());
		
		Panel northPanel = new Panel();
		northPanel.setHeight(32);
		borderPanel.add(northPanel,new BorderLayoutData(RegionPosition.NORTH));
		
		Menu menu = new Menu();  
		menu.setShadow(true);  
		menu.setMinWidth(10);
		
		
		CheckItem checkItem = new CheckItem();  
		checkItem.setText("I like Ext");  
		checkItem.setChecked(true);  
		
		menu.addItem(checkItem);  
		   
		CheckItem checkItem2 = new CheckItem();  
		checkItem2.setText("I also like GWT-Ext :)");  
		checkItem2.setChecked(true);  
          
        menu.addItem(checkItem2);  
		   
        CheckItem checkItem3 = new CheckItem();  
        checkItem3.setText("I donated");  
        checkItem3.setChecked(false);  
          
        menu.addItem(checkItem3);  
		  
        ToolbarButton menuButton  = new ToolbarButton("Menu");
        menuButton.setMenu(menu);
        Toolbar toolbar = new Toolbar();
        toolbar.addButton(menuButton);
        
        northPanel.add(toolbar);
		
		Panel southPanel = new HTMLPanel("<p>Lap trinh la cai quai gi?</p>");
		southPanel.setHeight(100);
		southPanel.setCollapsible(true);
		southPanel.setTitle("South");
		
		BorderLayoutData southData = new BorderLayoutData(RegionPosition.SOUTH);
		southData.setMinSize(100);
		southData.setMaxSize(200);
		southData.setMargins(new Margins(0, 0, 0, 0));
		southData.setSplit(true);
		borderPanel.add(southPanel,southData);
		
		Panel eastPanel = new Panel();
		eastPanel.setTitle("East");
		eastPanel.setCollapsible(true);
		eastPanel.setWidth(225);
		eastPanel.setLayout(new FitLayout());
		 String xml = "<Properties><Property><name>Name</name><type>2</type><default_value>Start</default_value></Property>";
		    xml += "<Property><name>Documentation</name><type>2</type><default_value>nothing</default_value></Property>";
		    xml += "<Property><name>Create Instances</name><type>1</type><default_value>1</default_value></Property></Properties>";
		
		BorderLayoutData eastData = new BorderLayoutData(RegionPosition.EAST);
		eastData.setSplit(true);
		eastData.setMinSize(150);
		eastData.setMaxSize(300);
		eastData.setMargins(new Margins(0,0,5,0));
		
		borderPanel.add(eastPanel,eastData);
		eastPanel.add(new Property(xml));
		
		
		Panel westPanel = new Panel();
		westPanel.setWidth(150);
		westPanel.setCollapsible(true);
		westPanel.setTitle("West");
		
		BorderLayoutData westData = new BorderLayoutData(RegionPosition.WEST);
		westData.setSplit(true);
		westData.setMinSize(175);
		westData.setMaxSize(400);
		westData.setMargins(new Margins(0,5,0,0));
		
		borderPanel.add(westPanel,westData);
		
		dragController = new BpelDragController(boundaryPanel);
	    dragController.setBehaviorMultipleSelection(false);
	    bpelPalete = new BpelPalette(dragController);
	    
	    westPanel.add(bpelPalete);
	    
	    Panel centerPanel = new Panel();
	    centerPanel.setTitle("Center");
	    centerPanel.setClosable(true);
	    centerPanel.setAutoScroll(true);
	    
	    borderPanel.add(centerPanel,new BorderLayoutData(RegionPosition.CENTER));
	    bpelDesign = new BpelDesignPanel();
	    centerPanel.add(bpelDesign);
		
		dropController = new BpelDropController(bpelDesign.getDesignPanel());
	    dragController.registerDropController(dropController);
		
	  
		panel.add(borderPanel);
		//initWidget(panel);
		boundaryPanel.add(panel);
		initWidget(boundaryPanel);
		new Viewport(panel);
	}
}
